<template>
	<view :class="currentTheme">
		<a-nabbar :name="title" />
		<view class="u-padding-32">
			<view  v-for="(data,index) in dataList" :key="index" @click="issueFan(data)" class="u-margin-bottom-20">
				<item-box padding="30">
					<view class="u-flex">
						<item-image :type="'1'" :img="data.userAvatar" :size="88" />
						<view class="content-desc-item u-font-32  u-margin-left-30">{{data.userName}}</view>
						<text v-if="form.inviteUserType"
							class="u-text-right content-desc-item u-font-26 fenshu">荣誉分：{{data.honorScore}}</text>
					</view>
				</item-box>
			</view>
			<empty v-if="dataList.length===0"></empty>
		</view>
		<fixed-team :btnText="submitTitle" @btnClick="addFan" v-if="form.inviteUserType"></fixed-team>
	</view>
</template>

<script>
	import {
		getList,
		add,
		deleteIds
	} from '@/api/crud.js'
	import empty from "@/components/mescroll-uni/components/mescroll-empty";
	export default {
		name: "index",
		components: {
			empty
		},
		data() {
			return {
				apiModule: 'shopApi',
				form: {
					inviteUserType: '',
					userType: ''
				},
				apiType: '',
				disabled: false,
				title: '',
				submitTitle: '加入粉丝团',
				dataList: [],
				customStyle: {
					borderRadius: '28rpx',
					background: '#765CFE',
					width: '162rpx'
				}
			}
		},

		onLoad(option) {
			if (option.userType == 'store') {
				if (option) this.form.userType = option.userType
				this.form.uid = option.uid
				this.apiType = 'fansGroup/getFansGroupByUid'
				this.title = '我加入的粉丝团'
			} else {
				if (option) this.form.inviteUserType = option.userType
				this.form.inviteUid = option.uid
				this.apiType = 'fansGroup'
				this.title = '发行的粉丝团'
				this.form.uid = ''
			}
			this.getList()
		},
		onShow() {
			console.log(22)
			this.getList()
		},
		methods: {
			// 跳转发行粉丝团列表
			issueFan(data) {
				this.$u.route({
					url: '/pagesA/fans/index',
					params: {
						uid: data.inviteUid,
						userType: 'issue',
					}
				})
			},
			fanList() {
				this.dataList.forEach(res => {
					if (res.uid == this.$store.getters.loginForm.uid) {
						// if(res.isInvite == 1) this.disabled = true
						this.submitTitle = '退出粉丝团'
					}
				})
			},
			getList() {
				getList(this.form, this.apiType, this.apiModule).then(res => {
					this.dataList = res.content
					if (this.form.inviteUserType) {
						this.fanList()
					}
				})
			},
			addFan() {
				this.loginValidate()
				//加入
				const item = this.$store.getters.loginForm
				if (this.submitTitle == '加入粉丝团') {
					let params = {
						inviteUid: this.form.inviteUid,
						inviteUserType: this.form.inviteUserType,
						uid: item.uid,
						userType: item.userType,
					}
					add(params, '/fansGroup/create', this.apiModule).then(res => {
						this.$u.toast('添加成功')
						this.getList()
					})
				} else {
					let res = this.dataList.filter(res => res.uid == item.uid)
					this.removeIds(res[0].id)
				}

			},
			//删除
			removeIds(id) {
				deleteIds('', 'fansGroup', this.apiModule, id).then(res => {
					this.$u.toast('退出成功')
					this.submitTitle = '加入粉丝团'
					this.getList();
				})
			},
		},
	}
</script>

<style scoped lang="scss">
	.fenshu {
		position: absolute;
		right: 59rpx;
	}

	/deep/.follow {
		height: 142rpx;
		background: #1F1B34;
		border-radius: 26rpx;
		width: 100%;
		margin-bottom: 26rpx;
		padding: 26rpx 33rpx;

		.typeone {
			color: #9596B8;
			margin-left: auto;
		}

		.customStyle {
			margin-left: auto;
			background-color: $primary;
			border: 1px solid $primary;
			width: 162rpx;
			height: 56rpx;
			border-radius: 50rpx;
			color: white;
			line-height: 56rpx;
			text-align: center;
		}
	}
</style>
